package club.emergency.wechat.question.search.consumer.service.fallback_factory;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.question.search.consumer.service.QuestionSearchConsumer;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.question.search.consumer.service.fallback_factory
 * Date: 2019/3/25
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Component
public class QuestionSearchFallbackFactory implements FallbackFactory<QuestionSearchConsumer> {
    @Override
    public QuestionSearchConsumer create(Throwable throwable) {
        return new QuestionSearchConsumer() {
            @Override
            public String getById(Long id) {
                return ResponseEntity.error(StatusCode.DB_SEARCH_ERROR, "根据id查询题目失败！", throwable.getMessage());
            }

            @Override
            public String flipListByCategoryAlias(String categoryAlias, Integer pageNo, Integer pageSize) {
                return ResponseEntity.error(StatusCode.DB_SEARCH_ERROR, "通过题目种类查询题目失败！", throwable.getMessage());
            }

            @Override
            public String getChoiceOptionByParent(Long parentId) {
                return ResponseEntity.error(StatusCode.DB_SEARCH_ERROR, "通过题目种类查询题目失败！", throwable.getMessage());
            }

            @Override
            public String getRandomQuestion(Integer size) {
                return ResponseEntity.error(StatusCode.DB_SEARCH_ERROR, "随机选题失败！", throwable.getMessage());
            }
        };
    }
}
